package cn.com.pc.content.config;


import cn.com.pc.content.domain.content.ContentRepository;
import cn.com.pc.content.mongo.CustomMongoRepositoryImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoTransactionManager;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableMongoRepositories(basePackages = "cn.com.pc.content.domain", repositoryBaseClass = CustomMongoRepositoryImpl.class)
@Configuration
@EnableTransactionManagement
public class MongoConfig {

    // 事务支持(不能同时支持mongoManager和jpaManager)
    @Bean(name = "mongoTransactionManager")
    @ConditionalOnProperty(name="spring.data.mongodb.transactionEnabled",havingValue = "true")
    MongoTransactionManager transactionManager(MongoDatabaseFactory factory){
        return new MongoTransactionManager(factory);
    }
}
